package com.lsf.dunlian.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.lsf.dunlian.R;
import com.lsf.dunlian.activity.MemberDetailActivity;
import com.lsf.dunlian.activity.MemberHanlerActivity;
import com.lsf.dunlian.entity.AllNoticeRecordData;
import com.lsf.dunlian.entity.BasicMember;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MemberListRecyclerViewAdapter extends RecyclerView.Adapter<MemberListRecyclerViewAdapter.ViewHolder> {
    private List<BasicMember> mDataList;
    private Context context;

    public MemberListRecyclerViewAdapter(List<BasicMember> mDataList, Context context) {
        this.mDataList = mDataList;
        this.context = context;
    }

    @NonNull
    @Override
    public MemberListRecyclerViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_member, parent, false);
        MemberListRecyclerViewAdapter.ViewHolder holder = new MemberListRecyclerViewAdapter.ViewHolder(view);
        return holder;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        BasicMember recordData = mDataList.get(position);
        holder.projectName.setText(recordData.getProject());
        holder.status.setText(recordData.getZhuangxiuJindu());
        holder.createName.setText(recordData.getName());
        holder.time.setText(recordData.getCreateTime().toString());
        int parseInt = Integer.parseInt(recordData.getZhuangxiuGongsi());
        holder.imgLayout.removeAllViews();
        for (int i = 0; i <parseInt ; i++) {
            holder.imgLayout.addView(LayoutInflater.from(context).inflate(R.layout.item_xing, null, false));
        }

        holder.layout.setOnClickListener(v -> {
            Intent intent = new Intent(context, MemberHanlerActivity.class);
            intent.putExtra("data",new Gson().toJson(recordData));
            context.startActivity(intent);
        });

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.projectName)
        TextView projectName;
        @BindView(R.id.status)
        TextView status;
        @BindView(R.id.createName)
        TextView createName;
        @BindView(R.id.time)
        TextView time;
        @BindView(R.id.imgLayout)
        LinearLayout imgLayout;
        @BindView(R.id.layout)
        LinearLayout layout;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
